package edu.msg.jthr.backend.bean;

import java.util.List;

import javax.ejb.EJB;
import javax.ejb.Stateless;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import edu.msg.jthr.backend.exception.ServiceException;
import edu.msg.jthr.backend.model.Comment;
import edu.msg.jthr.backend.repository.exception.RepositoryException;
import edu.msg.jthr.backend.repository.service.CommentRepository;
import edu.msg.jthr.backend.service.CommentService;

@Stateless(name="CommentServiceBean",mappedName = "ejb/CommentService")
public class CommentServiceBean implements CommentService {

	@EJB
	private CommentRepository commentRepository;
	private static Logger LOG = LoggerFactory
			.getLogger(CommentServiceBean.class);

	@Override
	public List<Comment> getAll() throws ServiceException {
		try {
			return commentRepository.getAll();
		} catch (RepositoryException e) {
			LOG.error("Get all comment error!" + e.getMessage());
			throw new ServiceException("Comment getById failure!", e);
		}
	}

	@Override
	public Comment getById(Long id) throws ServiceException {
		try {
			return commentRepository.getById(id);
		} catch (RepositoryException e) {
			LOG.error("Comment getById failure!" + e.getMessage());
			throw new ServiceException("Comment getById failure!", e);
		}
	}

	@Override
	public void create(Comment obj) throws ServiceException {
		try {
			commentRepository.create(obj);
		} catch (RepositoryException e) {
			LOG.error("Comment create failure!" + e.getMessage());
			throw new ServiceException("Comment create failure!", e);
		}
	}

	@Override
	public Comment update(Comment obj) throws ServiceException {
		try {
			return commentRepository.update(obj);
		} catch (RepositoryException e) {
			LOG.error("Comment update failure!" + e.getMessage());
			throw new ServiceException("Comment update failure!", e);
		}
	}

	@Override
	public void delete(Comment obj) throws ServiceException {
		try {
			commentRepository.delete(obj);
		} catch (RepositoryException e) {
			LOG.error("Comment delete failure!" + e.getMessage());
			throw new ServiceException("Comment delete failure!", e);
		}
	}
}